const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

async function checkProducts() {
  try {
    // 查询产品数据
    const products = await prisma.product.findMany({
      include: {
        category: true,
        inventoryRecords: {
          include: {
            warehouse: true
          }
        }
      }
    });

    console.log(`找到 ${products.length} 个产品`);
    
    if (products.length > 0) {
      // 输出第一个产品的详细信息
      console.log('第一个产品信息:');
      console.log(JSON.stringify(products[0], null, 2));
    }

    // 统计预警和缺货商品
    let warningProducts = 0;
    let outOfStockProducts = 0;
    
    products.forEach(product => {
      if (product.stockStatus === 'warning') {
        warningProducts++;
      } else if (product.stockStatus === 'out_of_stock') {
        outOfStockProducts++;
      }
    });
    
    console.log(`预警商品数量: ${warningProducts}`);
    console.log(`缺货商品数量: ${outOfStockProducts}`);
  } catch (error) {
    console.error('查询产品数据失败:', error);
  } finally {
    await prisma.$disconnect();
  }
}

checkProducts(); 